;As the name implies the empty statement really does nothing it has only compatiblity meaning (it should make no difference how many semicolons come after a valid statement).
Okay, now here come the statements that are of real use. First of all a statement may by an assignement expression, a function call expression or a IO operation expression:
<expr> ;Keep in mind that at this point <expr> does not mean any type of expression, e.g. 5+4; is not a valid statement like a=5+4;. The expression <expr> will be calculated and the result goes to nowhere.
In the following a valid stetement may be shorten by <stmt>
{ <stmt1> ; <stmt2> ;... }A block is a statement by itself it simply executes <stmt1> then <stmt2> and so on. You can use blocks, if you want to delay the execution of several statements, the commandline will wait until you have completed the block before it executes the statements inside. Usually you need blocks together with loops and conditionals.
In the following a valid block may be shorten by <block>
<type> <id1> , <id2> ,... ; <type> <id1> [ ] , <id2> [ ] ,... ; <type> <id> [ <num1> , <num2> ,... ] ; <type> <id> [ <num1> ] [ <num2> ]... ;Where <type> is one of the following: char, short, int, float, double, complex, string. Each type (execpt complex and string) is the Xi representation of the corresponding C-type, they should not be explained here. The type complex is simply a complex number which internally is two numbers of type double (the real and imaginary part). With a complex number you can do most of the things you can do with a double number. Because Xi does not understand pointers the string type is the equivalent to char * in C, except that you don'f have to bother with the memory allocation.
If you type a [ ] or [ <num1> , <num2> ,... ] or [ <num1> ] [ <num2> ]... after the variable name (<id>) Xi will generate an array of <type>. If you only use [] the array is of undefined dimension and the array consists of only one number. Alternatively you can explicitly set the dimension of the array (e.g. double a[10,10] will generate a 10x10 Matrix of double numbers).
<rettype> <id_f> ( <id1> , <id2> ,...) <block> <rettype> <id_f> ( <type> <id1> , <type> <id2> ,...) <block> <rettype> <id_f> ( <type> <id1> [ ] , <type> <id2> [ ] ,... ) <block>Where <rettype> indicates the type of the return value of the function <id_f>and may be one of the following: void (any type), char, short, int, float, double, complex, string, char[], short[], int[], float[], double[], complex[] (the latter indicating that the return value is an array). <id1>, <id2>,... are the parameters of the function. If no type is given the parameters are of type Any if this is not the case there will be a precise typechecking (alternatively you can think of a declaration). The '[]' after the <idn> indicates an array with arbitrary dimension (if you want to check the dimensions of the parameters you should use the size function). Note that it is necessary to specify a return type, but not the type of the parameters.
Of course a function can have a return value. For this purpose Xi has the return statement:
return ; return <expr> ;In the first case the function only returns (i.e. the statements after return will not be executed) in the second case the result of <expr> will be returned by the function. The result of <expr> might has to be cast to the given return type <rettype>, think of a build in cast expression (see Calculation Expression for detail).
Sometimes a function may have more than one return value. Since Xi supports no pointers it is necessary to define a special function definition:
[ <rettype1> , <rettype2> ,... ] <id_f> ( <params> ) <block>Here <params> should indicate the parameters as above. <rettype1>,<rettype2>,... are the types of the return values. To return more than one value an extended return statement is necessary:
return [ <expr1> , <expr2> ,... ] ;With this statement the function returns the values of <expr1>, <expr2>,... with the given types <rettype1>, <rettype2>,...
if ( <expr> ) <then-stmt> if ( <expr> ) <then-stmt> else <else-stmt>Usually <expr> is a comparison expression, the if statement tests whether the result of <expr> is true (i.e. it is not zero) It then executes <then-stmt>. If <expr> is false the if statement executes <else-stmt> when given.
for ( <begin-expr> ; <cond-expr> ; <after-expr> ) <stmt>The for statement first calculates <begin-expr> (usually this is an assignment that sets the start value of a counter). It then caluculates <cond-expr> and tests if the result is true (usually this is an abort condition for the counter). If so <stmt> will be executed and after this <after-expr> will be calculated (usually this is the increment of the counter). Now <cond-expr> will be tested again and if true stmt executed a second time and so on. The exection ends when the result of <cond-expr> is false.
The while-stmt is a little easier:
while ( <cond-expr> ) <stmt>The while statement simply executes <stmt> as long as the result of <cond-expt> is true.
The break statement causes the innermost enclosing loop to be left immediately. The continue statement causes the next iteration of the enclosing loop to begin.